package com.kclm.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

/**
 * @Author : lvhx
 * @Date: 2025/11/11 11:54
 * @Description:
 */
@Configuration
public class ApplicationConfig {
    @Bean
    public  DataSource dataSource(){
        DataSource dataSource = new DataSource();
        dataSource.setUrl("jdbc:mysql:///:3306/db1");
        dataSource.setDriver("com.mysql.cj.jdbc.Driver");
        dataSource.setUsername("root");
        dataSource.setPassword("123");
        return  dataSource;
    }
    @Bean
    @ConditionalOnBean(DataSource.class)
    public  DataCollectionService dataCollectionService(){
        DataCollectionService ds = new DataCollectionService();
        System.out.println("========dataSource"+dataSource());
        ds.setDataSource(dataSource());
        return  ds;
    }
}
